//
//  NYExamineTestActionCell.m
//  NiuWaJiaoYu
//
//  Created by 袁航 on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExamineTestActionCell.h"
@interface NYExamineTestActionCell ()
@property(nonatomic, strong) QMUIGhostButton *analysisBtn;
@property(nonatomic, strong) QMUIGhostButton *addGoodQuestBtn;
@end
@implementation NYExamineTestActionCell
+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return __WGHeight(63);
}
- (BOOL)shouldUpdateCellWithObject:(NICellObject *)object atIndexPath:(NSIndexPath *)indexPath
{
        self.indexPath = indexPath;
        self.questionModel = ( NYSubjectModel *)object.userInfo;
        return YES;
}
- (void)setQuestionModel:( NYSubjectModel *)questionModel
{
        _questionModel = questionModel;
        [self updateContent];
}
- (void)updateContent
{
        self.analysisBtn.enabled = (self.questionModel.is_test.integerValue == 2);
        self.analysisBtn.hidden = !self.analysisBtn.isEnabled;
        self.analysisBtn.ghostColor = self.analysisBtn.isEnabled ? UIColorHex(0x3696FF) : UIColorHex(0xDFDFDF);
        
        self.addGoodQuestBtn.enabled = (self.questionModel.is_good.integerValue == 1) && !self.analysisBtn.isHidden;
        self.addGoodQuestBtn.hidden = !self.addGoodQuestBtn.isEnabled  && !self.analysisBtn.isHidden;
        self.addGoodQuestBtn.ghostColor = self.addGoodQuestBtn.isEnabled ? UIColorHex(0x48CD57) : UIColorHex(0xDFDFDF);
}
- (void)setupView
{
        [super setupView];
        UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.analysisBtn,self.addGoodQuestBtn]];
        stackView.axis = UILayoutConstraintAxisHorizontal;
        stackView.distribution = UIStackViewDistributionFillEqually;
        stackView.alignment = UIStackViewAlignmentFill;
        stackView.spacing = 9;
        [self.contentView addSubview:stackView];
        [stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView).offset(__WGWidth(15));
                make.bottom.equalTo(self.contentView).offset(-__WGHeight(15));
                make.top.equalTo(self.contentView).offset(__WGHeight(15));
                make.right.equalTo(self.contentView).offset(-__WGWidth(150));
        }];
        @weakify(self);
        [self.analysisBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYExamineTestActionTypeAnalysis, self.questionModel);
                }
        }];
        [self.addGoodQuestBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYExamineTestActionTypeAddToGood, self.questionModel);
                }
        }];
}
- (QMUIGhostButton *)analysisBtn
{
        if ( _analysisBtn == nil )
        {
                _analysisBtn = [[QMUIGhostButton alloc] init];
                _analysisBtn.ghostColor = UIColorHex(0x48CD57);
                _analysisBtn.cornerRadius = 3;
                _analysisBtn.clipsToBounds = YES;
                _analysisBtn.titleLabel.font = WGSystem14Font;
                [_analysisBtn setTitle:@"查看解析" forState:(UIControlStateNormal)];
        }
        return _analysisBtn;
}
- (QMUIGhostButton *)addGoodQuestBtn
{
        if ( _addGoodQuestBtn == nil )
        {
                _addGoodQuestBtn = [[QMUIGhostButton alloc] init];
                _addGoodQuestBtn.ghostColor = UIColorHex(0x3696FF);
                _addGoodQuestBtn.cornerRadius = 3;
                _addGoodQuestBtn.clipsToBounds = YES;
                _addGoodQuestBtn.titleLabel.font = WGSystem14Font;
                [_addGoodQuestBtn setTitle:@"加入好题本" forState:(UIControlStateNormal)];
        }
        return _addGoodQuestBtn;
}
@end
